// import isEmpty from 'lodash/isEmpty'
import { Toast } from 'vant'
export default function pdaMatchPageData({ vm, action, done, callbackData }) {

  //分页器组件ID
  let moduleId = action.extension.paginationSelect.value[0]
  //配置动作
  let config = action.extension

  console.log("分页器匹配数据操作vmvmvmvmvm", vm)

  console.log("分页器匹配数据操作action", action)

  console.log("分页器匹配数据操作callbackData", callbackData)

  console.log("vm.vuiComponents[moduleId].self", vm.vuiComponents[moduleId].self)

  //取分页器所有数据
  let dataArr = vm.vuiComponents[moduleId].self.formDataPage;
  //取配置KEY
  let fromDataKey = config.matchFromDataKey.value
  let toDataKey = config.matchToDataKey.value
  console.log('fromDataKey', fromDataKey)
  console.log('dataKey', toDataKey)
  //取出表单对应module的值
  let itemData = callbackData[fromDataKey]
  console.log('itemData', itemData)
  //定义返回表单值
  let formData = {}

  let pageIndex = -1

  dataArr.forEach((item, index) => {
    //如果匹配上，则给抛值
    if (itemData === item[toDataKey]) {
      pageIndex = index
      formData = dataArr[index]
    }
  });

  console.log("pageIndex", pageIndex)
  //如果一个都不匹配,则提示报错
  if (pageIndex == -1) {
    Toast('匹配字段ID有误,请检查')
    done(null, {})
    return
  }

  //切换分页器页码
  vm.vuiComponents[moduleId].self.currentPage = pageIndex + 1

  done(null, formData)
}
